<template>
	<div class="container">
		<!-- 路径导航区域 -->
		<el-breadcrumb separator="/">
			<el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
			<el-breadcrumb-item>咨询回复管理</el-breadcrumb-item>
		</el-breadcrumb>
		<!-- 搜索区域 -->
		<el-row>
			<el-form :inline="true">
				<el-form-item label="咨询内容">
					<el-input v-model="queryInfo.content" placeholder="请输
入咨询内容" clearable @clear="queryList"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="queryList">搜索</el-button>
					<el-button type="danger">批量删除</el-button>
				</el-form-item>
			</el-form>
		</el-row>
		<!-- 表格区域 -->
		<el-table :data="consultReplyList" border style="width: 100%">
			<el-table-column type="selection" width="55"></el-table-column>
			<el-table-column prop="id" label="ID"></el-table-column>
			<el-table-column prop="content" label="咨询内容">
			</el-table-column>
			<el-table-column prop="user.username" label="用户">
			</el-table-column>
			<el-table-column prop="reply" label="回复">
			</el-table-column>
			<el-table-column prop="consult.name" label="咨询师">
			</el-table-column>
			<el-table-column prop="createTime" label="创建时间">
			</el-table-column>
			<el-table-column label="操作">
				<template slot-scope="scope">
					<el-link type="primary" @click="toEditConsultReply(scope.row)">编辑回复</el-link>&nbsp;
					<el-link type="primary" @click="deleteConsultReply(scope.row.id)">删除回复</el-link>
				</template>
			</el-table-column>
		</el-table>
		<!-- 分页区域 -->
		<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
			:current-page="queryInfo.pageNum" :page-sizes="[5, 10, 15, 20]" :page-size="queryInfo.pageSize"
			layout="total, sizes, prev, pager, next, jumper" :total="total">
		</el-pagination>

		<!-- 新增和修改的对话框 -->
		<el-dialog :title="title" :visible.sync="dialogFormVisible" @close="cancle">
			<el-form :model="consultReply">
				<el-form-item label="回复详情" label-width="80px">
					<quill-editor v-model="consultReply.reply"></quill-editor>
				</el-form-item>

			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click="cancle">取 消</el-button>
				<el-button type="primary" @click="editConsultReply">确 定</el-button>
			</div>
		</el-dialog>
		
	</div>
</template>
<script>
	export default {
		data() {
			return {
				// 查询信息对象
				queryInfo: {
					content: '',
					pageNum: 1,
					pageSize: 10
				},
				total: 183,
				consultReplyList: [],
				title: '', // 对话框标题
				dialogFormVisible: false, // 是否显示对话框
				consultReply: {
					"id": '',
					"content": '',
					"user_id": 0,
					"reply": '',
					"consult_id": 0,
					"createTime": ''

				}
			}
		},
		methods: {
			deleteConsultReply(id) {
			   this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
			     confirmButtonText: '确定',
			     cancelButtonText: '取消',
			     type: 'warning'
			  })
			  .then(() => {
			      this.$http.delete('consultReply/delete/' + id)
			          .then(resp => {
			          if (resp.data.status == 200) {
			             this.$message.success(resp.data.message)
			              this.queryList()
			           } else {
			             this.$message.error(resp.data.message)
			            }
			           })
			       })
			        .catch(() => {
			          this.$message({
			            type: 'info',
			            message: '已取消删除'
			          })
			        })
			    },
			handleSizeChange(size) {
				//console.log('每页显示数量发生改变');
				this.queryInfo.pageSize = size;
				this.queryInfo.pageNum = 1;
				// 重新查询
				this.queryList()
			},
			handleCurrentChange(num) {
				//console.log('页码发生改变');
				this.queryInfo.pageNum = num;
				// 重新查询
				this.queryList();
			},
			// 分页查询信息的方法
			queryList() {
				// 调用后端接口来获取数据
				this.$http.get('consultReply/findByPage', {
						params: this.queryInfo
					})
					.then(resp => {
						if (resp.data.status == 200) {
							console.log(resp.data)
							this.consultReplyList = resp.data.data.list;
							this.total = resp.data.data.total;
							//console.log(this.consultReplyList)
						} else {
							this.$message.error('查询失败！')
						}
					})
			},
			// 进入修改的预览数据页面
			toEditConsultReply(row) {
				//console.log(row)
				// 赋值
				this.consultReply = row;
				// 设置标题
				this.title = "编辑回复";
				// 开启对话框
				this.dialogFormVisible = true;

			},
			cancle() {
				this.dialogFormVisible = false;
				this.consultReply={
					"id": '',
					"content": '',
					"user_id": 0,
					"reply": '',
					"consult_id": 0,
					"createTime": ''
				
				}
			},
			editConsultReply() {
				this.$http.put("consultReply/update", this.consultReply)
					.then(resp => {
						if (resp.data.status == 200) {
							// 消息提示
							this.$message.success('修改成功！');
							// 清空数据
							this.consultReply={
								"id": '',
								"content": '',
								"user_id": 0,
								"reply": '',
								"consult_id": 0,
								"createTime": ''
							
							}
							// 关闭对话框
							this.dialogFormVisible = false;
							// 重新查询
							this.queryList()
						} else {
							this.$message.error('接口异常！')
						}
					})
			}
			},
			mounted() {
				this.queryList();
			}
		}
</script>
<style>
	.ql-container{
		min-height: 200px;
	}
	.el-breadcrumb {
		margin-bottom: 15px;
		padding: 0 0 15px;
		border-bottom: 1px solid #ddd;
	}

	.el-pagination {
		margin-top: 15px;
	}

	.el-link {
		padding: 0 5px;
	}
</style>